package blue.mqtt4j.client;

/**
 * MQTT QoS
 *
 * @author Jin Zheng
 * @since 1.0 2020-09-30
 */
public enum MqttQoS
{
	/**
	 * 最多一次
	 */
	AT_MOST_ONCE(0),

	/**
	 * 最少一次
	 */
	AT_LEAST_ONCE(1),

	/**
	 * 只有一次
	 */
	EXACTLY_ONCE(2);

	private int value;

	MqttQoS(int value)
	{
		this.value = value;
	}

	public static MqttQoS valueOf(int value)
	{
		for (MqttQoS mqttQoS : MqttQoS.values())
		{
			if (mqttQoS.value == value)
			{
				return mqttQoS;
			}
		}
		return null;
	}

	public static MqttQoS valueOf(io.netty.handler.codec.mqtt.MqttQoS nettyMqttQoS)
	{
		return valueOf(nettyMqttQoS.value());
	}

	public io.netty.handler.codec.mqtt.MqttQoS toNettyMqttQoS()
	{
		return io.netty.handler.codec.mqtt.MqttQoS.valueOf(value);
	}

	public int value()
	{
		return value;
	}

}
